############################################################
# Makefile for the regression tests that are run on travis
############################################################
ROOT = ../../../..

test-documentation:
	(cd $(ROOT)/Buildings; ../bin/runUnitTests.py --validate-html-only)
	(cd $(ROOT)/Buildings/Resources/Documentation/userGuide; make regressiontest)
	(cd $(ROOT)/Buildings/Resources/src/fluid/heatpumps/calibration/doc; make regressiontest)

test-experiment-setup:
	(cd $(ROOT)/Buildings; ../bin/runUnitTests.py --validate-experiment-setup)

test-autogenerated-files:
	#echo ### Check for package.order to be up to date
	(cd  $(ROOT)/Buildings; \
	  python -c 'import buildingspy.development.refactor as r; \
	  r.write_package_order(".", recursive=True)'; \
	  git diff --exit-code . )

	#echo ### Verify that all OpenModelica scripts are up to date, and no old scripts exist
	(cd  $(ROOT)/Buildings && \
	  rm Resources/Scripts/OpenModelica/compareVars/*.mos && \
	  python -c 'import buildingspy.development.regressiontest as u; \
	  u.Tester().writeOpenModelicaResultDictionary()')
	git status --porcelain $(ROOT)/Buildings/Resources/Scripts/OpenModelica;
	test -z "$$(git status --porcelain $(ROOT)/Buildings/Resources/Scripts/OpenModelica)"

	#echo ### Check for UnitConversion package to be consistent with the script that generates it
	(cd  $(ROOT); \
	  python Buildings/Resources/src/Controls/OBC/UnitConversions/unit_converters.py; \
	  git diff --exit-code Buildings)

test-verify-files:
	(cd $(ROOT)/Buildings && ../bin/verifyFiles.py)

# Test whether all EnergyPlus validation files are up to date.
# This targets searches all files `run.sh` and executes them.
test-energyplus-validations:
	export PATH=$(ROOT)/ENERGYPLUS_VERSION:$(PATH)
	(cd $(ROOT)/Buildings/Resources/Data && \
	for ff in `find . -name run.sh`; do; \
	(echo "*** Testing $ff" && cd `dirname $ff` && ./run.sh);
	done; \
	cd $(ROOT)/Buildings/Resources/Data && \
	git diff --exit-code .)

test-dymola:
	(cd $(ROOT)/Buildings && \
	  python ../bin/runUnitTests.py --batch --single-package $(PACKAGE) --tool dymola)

test-optimica:
	(cd $(ROOT)/Buildings && \
	  export PYTHONPATH=$(TRAVIS_BUILD_DIR)/Buildings/Resources/Python-Sources && \
	  python ../bin/runUnitTests.py --batch --single-package $(PACKAGE) --tool optimica --skip-verification)

test-jmodelica:
	(cd $(ROOT)/Buildings && \
	  export PYTHONPATH=$(TRAVIS_BUILD_DIR)/Buildings/Resources/Python-Sources && \
	  python ../bin/runUnitTests.py --batch --single-package $(PACKAGE) --tool jmodelica --skip-verification)
